<#include "../public/header.html">


    <div id="editdlg">
    </div>
    <div class="easyui-layout" style="width:100%;height:100%;">
        <div id="p" data-options="region:'west',tools:tools" title="组织机构" style="width:20%;padding:10px">
            <ul id="tt" class="easyui-tree" data-options="url:'admin/department/combotree',method:'get',animate:true,onClick:tree_select"></ul>
        </div>
        <div data-options="region:'center'" title="组织机构列表">
            <div id="tb" style="padding:5px 5px; border-bottom: dashed #d2d2d2 1px;margin-bottom: 5px;">
                单位名称: <input class="easyui-textbox" style="width:110px" id="dep_name">
                <a href="javascript://" class="easyui-linkbutton" iconCls="icon-search" onclick="search_but()">搜索</a>
            </div>
            <table id="list" class="easyui-datagrid" style="width:100%;height:100%"
                   sortName="id"
                   sortOrder="asc"
                   rownumbers="true"
                   pagination="true"
                   pagesize="50"
                   singleSelect="true"
                   data-options="url:'admin/department/listJson',toolbar:toolbar">
                <thead>
                <tr>
                    <th field="parent_name" width="100" sortable="true">归属</th>
                    <th field="dep_name" width="100" sortable="true">单位名称</th>
                    <th field="charge_person" width="80" align="right" sortable="true">负责人</th>
                    <th field="tel_phone" width="80" align="right" sortable="true">移动电话</th>
                    <th field="mobile_phone" width="80" align="right" sortable="true">固话</th>
                    <th field="kw_charge_person" width="80" align="right" sortable="true">联系人</th>
                    <th field="kw_tel_phone" width="80" align="right" sortable="true">联系电话</th>
                    <th field="kw_mobile_phone" width="80" align="right" sortable="true">固话</th>
                    <th field="address" width="80" align="right" sortable="true">店铺地址</th>
                    <th field="www_address" width="80" align="right" sortable="true">网址</th>
                    <th field="create_datetime" width="130" align="right" sortable="true">创建时间</th>
                </tr>
                </thead>
            </table>


        </div>
    </div>


    <script type="text/javascript">
        var id ;
        var content;
        var p_id;
        var tree_note;

        $(function(){
            $("#tb").prependTo(".datagrid-toolbar");
        });

        var tools = [{
            id:30501,
            disabled:"${((permission_button.p30501!) == 'true')? string('','true')}",
            iconCls:'icon-add',
            handler:function(){
                $("#editdlg").dialog({
                    title:"创建分类",
                    iconCls: 'icon-edit',
                    width: 400,
                    height: 200,
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/department/add_type",
                    onLoad:function() {

                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#editForm').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#editForm').form('submit',{
                                url:"admin/department/save",
                                dataType:"json",
                                onSubmit:function(){
                                    return $(this).form('enableValidation').form('validate');
                                },
                                success:function(data){
                                    var data = eval('(' + data + ')');  // change the JSON string to javascript object

                                    $.messager.alert('提示',data.msg);
                                    if(data.success==1){
                                        $("#editdlg").dialog("close");
                                        $("#tt").tree("reload");
                                    }
                                }
                            });
                        }
                    }]
                });
            }
        },{
            id:30501,
            disabled:"${((permission_button.p30501!) == 'true')? string('','true')}",
            iconCls:'icon-edit',
            handler:function(){
                if(tree_note === undefined){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择要编缉的类型',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }
                if(tree_note.pid != 1){
                    $.messager.show({
                        title:'提醒',
                        msg:'只能编缉二级分类',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

                $("#editdlg").dialog({
                    title:"编缉",
                    iconCls: 'icon-edit',
                    width: 400,
                    height: 200,
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/department/edit_type?id="+tree_note.id,
                    onLoad:function() {
                        $.messager.progress('close');
                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#editForm').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#editForm').form('submit',{
                                url:"admin/department/save",
                                dataType:"json",
                                onSubmit:function(){
                                    return $(this).form('enableValidation').form('validate');
                                },
                                success:function(data){
                                    $.messager.alert('提示',data.msg);
                                    if(data.success==1){
                                        $("#editdlg").dialog("close");
                                        $("#tt").tree("reload");
                                    }
                                }
                            });
                        }
                    }]
                });
            }
        }];

        var toolbar = [{
            id:10301,
            disabled:"${((permission_button.p10301!) == 'true')? string('','true')}",
            text:'添加',
            iconCls:'icon-add',
            handler:function(){

                $("#editdlg").dialog({
                    title:"添加",
                    iconCls: 'icon-edit',
                    width: '100%',
                    height: '100%',
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/department/edit",
                    onLoad:function() {
                        $.messager.progress('close');
                        if(p_id !== undefined){
                            $('#parent_id').combotree('setValues', [p_id]);
                        }
                        $('#status').combobox("setValues",[1])
                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#editForm').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#editForm').form('submit',{
                                url:"admin/department/save",
                                dataType:"json",
                                onSubmit:function(){
                                    $("#introduction").text(content.html());
                                    return $(this).form('enableValidation').form('validate');
                                },
                                success:function(data){
                                    var data = eval('(' + data + ')');  // change the JSON string to javascript object

                                    alert(data.msg);
                                    $("#editdlg").dialog("close");
                                    $("#list").datagrid("reload");
                                    $("#tt").tree("reload");

                                }
                            });
                        }
                    }]
                });
            }
        },{
            id:10302,
            disabled:"${((permission_button.p10302!) == 'true')? string('','true')}",
            text:'编缉',
            iconCls:'icon-edit',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择要编缉的行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

               $("#editdlg").dialog({
                   title:"编缉",
                   iconCls: 'icon-edit',
                   width: '100%',
                   height: '100%',
                   closed: false,
                   cache: false,
                   modal: true,
                   href:"admin/department/edit?id="+note.id,
                   onLoad:function() {
                       $.messager.progress('close');
                   },
                   buttons: [{
                       text: '取消',
                       iconCls:'icon-cancel',
                       handler: function () {
                           $('#editForm').form('clear');
                           $("#editdlg").dialog("close");
                       }
                   },{
                       text: '保存',
                       iconCls: 'icon-ok',
                       handler: function () {
                           $('#editForm').form('submit',{
                               url:"admin/department/save",
                               dataType:"json",
                               onSubmit:function(){
                                   $("#introduction").text(content.html());
                                   return $(this).form('enableValidation').form('validate');
                               },
                               success:function(data){
                                   var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                   alert(data.msg);
                                   $("#editdlg").dialog("close");
                                   $("#list").datagrid("reload");
                                   $("#tt").tree("reload");

                               }
                           });
                       }
                   }]
               });
            }
        },{
            text:'查看',
            iconCls:'icon-view',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择要编缉的行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

                $("#editdlg").dialog({
                    title:"查看",
                    iconCls: 'icon-edit',
                    width: 700,
                    height: 500,
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/department/view?id="+note.id,
                    onLoad:function() {
                        $.messager.progress('close');
                    },
                    buttons: []
                });
            }
        }];

        function search_but(){
           $("#list").datagrid("reload",{dep_name:$("#dep_name").val()});
        }

        function tree_select(note){
            tree_note = note;
            $("#list").datagrid("reload",{dep_name:$("#dep_name").val(),parent_id:note.id});
            p_id = note.id;
        }
    </script>
    <#include "../public/footer.html">